/*
 * MIT License
 * 
 * Copyright (c) 2017 wen.gu <454727014@qq.com>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: tiny_queue.h
 *
 * Purpose: tiny queue data structure and API
 *
 * Developer:
 *   wen.gu , 2017-03-21
 *
 * TODO: 
 *
 ***************************************************************************/

#ifndef __TINY_QUEUE_H__
#define __TINY_QUEUE_H__


#include "general_type.h"


#ifdef __cplusplus
extern "C" {
#endif

/***************************************************************************
 *
 * macro declaration
 *
 ***************************************************************************/

/***************************************************************************
 *
 * data structure declaration
 *
 ***************************************************************************/

/** the callback function for free item */
typedef void (*tfQueueItemFreeFunc_t)(void* item);
/***************************************************************************
 *
 * API declaration
 *
 ***************************************************************************/

/**
 *@brief  create a queue instance 
 *
 *@param  none
 *
 *@return success: queue instance handle, fail: NULL.
 *@see
 *
 */
G_API GPHD tfQueueCreate(void);

/**
 *@brief  destroy a queue instance 
 *
 *@param  queue [in] pointer to queue instance
 *
 *@return none.
 *@see
 *
 */
G_API void tfQueueDestroy(GPHD queue);

/**
 *@brief  clear(remove and free) all item in queue
 *
 *@param  queue     [in] pointer to queue instance
 *@param  item_free [in] callbck function for free item.
 *
 *@return none.
 *@see
 *
 */
G_API void tfQueueClear(GPHD queue, tfQueueItemFreeFunc_t item_free);

/**
 *@brief  append a item to current queue.
 *
 *@param  queue [in] pointer to queue instance
 *@param  item  [in] pointer new item.
 *
 *@return success: GTRUE, fail: GFALSE
 *@see
 *
 */
G_API GBOL tfQueueEnQueue(GPHD queue, void* item);

/**
 *@brief  pop a item from current queue 
 *
 *@param  queue [in] pointer to queue instance
 *
 *@return success: item handle, fail: NULL.
 *@see
 *
 */
G_API void *tfQueueDeQueue(GPHD queue);

/**
 *@brief  get the count of item in current queue.
 *
 *@param  queue [in] pointer to queue instance
 *
 *@return how many item in current queue.
 *@see
 *
 */
G_API GU32 tfQueueLength(GPHD queue);




#ifdef __cplusplus
}
#endif

#endif //end of __TINY_QUEUE_H__
